//
//  CLOrderListViewController.swift
//  CLEasyBBQ
//
//  Created by simon zhao on 2017/4/5.
//  Copyright © 2017年 simon zhao. All rights reserved.
//

import UIKit

class CLOrderListViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{
    
    let reustr : String = "clorderCell"
    let dataArr : [String] = ["西城时代A3地块2栋2412"]
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = "订单列表"
        
        let noticeView = self.getHeaderView()
        self.view.addSubview(noticeView)
        
        let odTableview = UITableView.init(frame: CGRect(x:0,y:noticeView.frame.maxY,width:self.view.frame.size.width,height:self.view.frame.size.height - noticeView.frame.size.height - 108))
        odTableview.delegate = self
        odTableview.dataSource = self
        odTableview.register(UINib.init(nibName: "ClOrderShowTableViewCell", bundle: nil), forCellReuseIdentifier: reustr)
        odTableview.separatorStyle = UITableViewCellSeparatorStyle.none
        view.addSubview(odTableview)
        

        

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func getHeaderView() -> UIView {
        
        let headerView = UIView.init(frame: CGRect(x:0,y:64,width:self.view.frame.size.width,height:self.view.frame.size.height * 0.06))
        headerView.backgroundColor = UIColor.rgbColorFromHex(rgb: 0xEDEDED)
        
        
        let bellImageView = UIImageView.init(image: UIImage.init(named: "notice"))
        let noticeLabel = UILabel()
        noticeLabel.textColor = UIColor.orange
        noticeLabel.text = "收到 5 个新订单"
        headerView.addSubview(bellImageView)
        headerView.addSubview(noticeLabel)
        
        
        bellImageView.snp.makeConstraints { (make) in
            
            make.left.equalTo(headerView).offset(10)
            make.height.equalTo(headerView.frame.size.height * 0.6)
            make.width.equalTo(headerView.frame.size.height * 0.6)
            make.top.equalTo(headerView.frame.size.height * 0.2)
            
        }
        
        noticeLabel.snp.makeConstraints { (make) in
            
            make.left.equalTo(bellImageView.snp.right).offset(20)
            make.height.equalTo(bellImageView)
            make.width.equalTo(headerView.frame.size.width * 0.5)
            make.top.equalTo(bellImageView)
            
        }
        
        
        return headerView
        
    }
    
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

extension  CLOrderListViewController {

    @objc(numberOfSectionsInTableView:) func numberOfSections(in tableView: UITableView) -> Int {
        
        return 1
        
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return 6
    }
    
    @objc(tableView:heightForRowAtIndexPath:) func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 120
    }
    
    @objc(tableView:cellForRowAtIndexPath:) func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell : ClOrderShowTableViewCell = tableView.dequeueReusableCell(withIdentifier: reustr) as! ClOrderShowTableViewCell
        cell.locationLabel.text = dataArr[0]
        cell.timeLabel.text = self.getTimeNow()
        cell.numLabel.text = String(indexPath.row + 1)
        return cell
    }
    
    @objc(tableView:didSelectRowAtIndexPath:) func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
//        self.navigationController?.pushViewController(CLOrderDetailViewController(), animated: true)
        self.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(CLOrderDetailViewController.init(titleName: "订单详情", leftimageName: "itemBack", rightImageName: "Order_tel"), animated: true)
        self.hidesBottomBarWhenPushed = false
    }
    
    func getTimeNow() -> String {
        
        let formatter: DateFormatter = DateFormatter()
        formatter.dateFormat = "yyyy年MM月dd日 HH点mm分"
        return formatter.string(from: Date.init(timeIntervalSinceNow: 0))
    }

}
